import java.io.IOException;
import java.io.Writer;
import java.util.List;
import java.util.Map;

import com.csvreader.CsvWriter;

public class Object2CSV {

	
	public static <K,V> void listToCsv(List<Map<K, V>> mapList, Writer out,char delimeter) throws IOException{
		CsvWriter csvOutput = null;
		try {
			csvOutput = new CsvWriter(out, delimeter);
			for(Map<K, V> map:mapList){
           	    for(Map.Entry<K, V> e : map.entrySet()) {
           		    //e.getKey().toString()
                    //e.getValue().toString()
           	     if (e.getValue() == null)
                 {
           	    	csvOutput.write("");
                	 }
                	 else
                	 {
                		 csvOutput.write(e.getValue().toString());
                	 }
                    
                }
           	    csvOutput.endRecord();
           }
			
			
		}finally {
                if (csvOutput != null) {
                    try { csvOutput.close() ; } catch(Exception e) { /* ignore */ }      
                }
        }// end inner finally
	}
	

}
